<?php

class Storage_Pathtype_Dynamic
{
	function generate($params)
	{
		
		if(!isset($file_id)){
			$file_id = mt_rand(0, 0xFFFFFFFFFFFFFFFF);
		}
		extract($params);

		$path = 'public' . '/';
		$path .= $parent_type . '/';
		$base = 255;
		$tmp = $file_id;

		// Generate subdirs while id > $base
		do
		{
			$mod = ($tmp % $base);
			$tmp -= $mod;
			$tmp /= $base;
			$path .= sprintf("%02x", $mod) . '/';
		}
		while( $tmp > 0 );

		$path .= sprintf("%04x", $file_id) . '_' . substr($hash, 4, 4) . '.' . $extension;

		return $path;
	}

}
